using FreeSql.DataAnnotations;

namespace SumerCoreDevOps.Domain.Entities;

/// <summary>
/// 流水线
/// </summary>
[Table(Name = "pipelines")]
[Index("idx_workflow", nameof(WorkflowDefinitionId), false)]
[Index("idx_repo", nameof(RepositoryUrl), false)]
public class Pipeline
{
    [Column(IsPrimary = true, IsIdentity = true)]
    public long Id { get; set; }

    /// <summary>
    /// 流水线名称
    /// </summary>
    [Column(StringLength = 200)]
    public string Name { get; set; } = null!;

    /// <summary>
    /// 工作流定义ID
    /// </summary>
    public long WorkflowDefinitionId { get; set; }

    /// <summary>
    /// Git仓库地址
    /// </summary>
    [Column(StringLength = 500)]
    public string RepositoryUrl { get; set; } = null!;

    /// <summary>
    /// 分支名称
    /// </summary>
    [Column(StringLength = 100)]
    public string Branch { get; set; } = "main";

    /// <summary>
    /// 是否启用
    /// </summary>
    public bool IsEnabled { get; set; } = true;

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 更新时间
    /// </summary>
    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

    /// <summary>
    /// 创建人
    /// </summary>
    [Column(StringLength = 100)]
    public string? CreatedBy { get; set; }

    /// <summary>
    /// 工作流定义
    /// </summary>
    [Navigate(nameof(WorkflowDefinitionId))]
    public WorkflowDefinition WorkflowDefinition { get; set; } = null!;

    /// <summary>
    /// 流水线实例列表
    /// </summary>
    [Navigate(nameof(PipelineInstance.PipelineId))]
    public List<PipelineInstance> Instances { get; set; } = [];
}
